package com.working.home.ui

import androidx.lifecycle.liveData
import com.working.home.data.remote.HomeServices
import com.working.libbase.base.BaseViewModel
import com.working.libbase.model.ArticleResponse
import com.working.libcommon.adapter.PagingDataSource

class HomeViewModel(private val homeServices: HomeServices) : BaseViewModel() {

    val dataSource: PagingDataSource<ArticleResponse> = PagingDataSource {
        if (it.pageNo == 0) homeServices.topArticles().data?.apply {
            forEach { response ->
                response.top = true
            }
        } else
            homeServices.article(it.pageNo - 1).data?.datas
    }

    val banner = liveData { emit(homeServices.banner()) }
}